package com.rcadmin.busi.web.action;

import java.util.HashMap;
import java.util.Map;

import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.servlet.ModelAndView;

import com.rcadmin.busi.web.ddl.WebImage;
import com.rcadmin.common.contant.SysParamCode;
import com.rcadmin.core.app.session.SessionException;
import com.rcadmin.core.jpa.util.PageBean;
import com.rcadmin.core.web.BaseAction;

/**
 * 图片管理展示类
 * 
 * @author tanson lam
 * @creation 2015年1月10日
 */
@Controller
public class ImageController extends BaseAction {

	private static final String LIST_PAGE = "/web/image/imglist";
	private static final String EDIT_FORM = "/web/image/imgupload";

	/**
	 * 查詢列表
	 * 
	 * @throws SessionException
	 */
	@GetMapping("/image/show.op")
	public ModelAndView show() {
		Map<String, Object> dataModel = new HashMap<String, Object>();
		String condition = "user_id=" + getLoginUserId() + bulidConditionSql();
		PageBean<WebImage> pageBean = baseModelService.pageQuery(condition,
				bulidOrderBySql(), getPageSize(), getPage(), WebImage.class);
		pageBean.setPageUrl(getPaginationUrl("/image/show.op"));
		dataModel.put("pageBean", pageBean);
		return render(LIST_PAGE, dataModel);
	}

	/**
	 * 显示编辑表单
	 */
	@GetMapping("/image/showEditForm.op")
	public ModelAndView showEditForm() {
		Map<String, Object> dataModel = new HashMap<String, Object>();
		String id = request.getParameter("id");
		if (!StringUtils.isEmpty(id)) {
			WebImage webImage = baseModelService.findOne(Integer.valueOf(id),
					WebImage.class);
			dataModel.put("bean", webImage);
		}
		dataModel.put("iseffCode",
				sysParamService.getSysParamByRoot(SysParamCode.ISEFF));
		return render(EDIT_FORM, dataModel);
	}
}
